package com.cyd.springboot02.service;

import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;
import org.springframework.util.concurrent.ListenableFuture;

/**
 * @ClassName : com.cyd.springboot02.service.HelloServiceImpl
 * @Description : 类描述
 * Created by cyd on 2021-05-20 22:08:00
 */
@Component
public class HelloServiceImpl {
    @Async
    public void sayHello(String name) {
        LoggerFactory.getLogger(HelloServiceImpl.class).info(name + ":Hello World!");
    }

    @Async(value = "oneOtherTaskExecutor")
    public void sayBye(String name) {
        LoggerFactory.getLogger(HelloServiceImpl.class).info(name + ":Hello World!");
    }

    @Async
    public ListenableFuture<String> sayFuture(String name) {
        String res = name + ":Hello Future!";
        LoggerFactory.getLogger(HelloServiceImpl.class).info(name + ":Hello World!");
        return new AsyncResult<>(res);
    }

}
